<template>
  <el-dialog
      :visible.sync="loginVisible"
      title="Login"
      :modal="false"
      :close-on-click-modal="false"
      :before-close="handleLoginClose">
    <div class="content">
      <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="账号" prop="username">
            <el-input v-model="ruleForm.username"  autocomplete="new-username" datalist></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input type="password" v-model="ruleForm.password"  autocomplete="new-password" datalist></el-input>
        </el-form-item>
      </el-form>
      <div class="pay-btn">
        <el-button @click="handleAdminLogin">Login</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>

import {adminLogin} from "../api/shopMall";

export default {
  name: "login",
  props:{
    loginVisible:{
      type:Boolean,
      defaulted:false
    }
  },
  data(){return{
    ruleForm: {
      username: '',
      password: '',
    },

    rules:{
      username: [
        { required: true, message: '请输入账号', trigger: 'blur' }
      ],
      password: [
        { required: true, message: '请输入密码', trigger: 'blur' }
      ],
    }
  }},
  methods:{
    handleAdminLogin(){
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          console.log(this.ruleForm)
          adminLogin(this.ruleForm).then(res => {
            if(res.data.code!=200){
              this.$message({
                type:'error',
                message:'Login failed,please check your Username/Password!'
              });
              return false

            }
            console.log(res)
            this.$emit('handleAdminLogin',{isManager:res.data.manager,store_id:res.data.storeid,stuffid:res.data.stuffid})
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });

    },

    handleLoginClose(){
      this.$emit('handleLoginClose')
    }
  }
}
</script>

<style scoped lang="scss">
::v-deep .el-dialog{
  width: 490px;
  height: 300px;
  background: rgba(0, 0, 0, 0.9);
  border-radius: 38px;
}
  .content{
    text-align: center;
    img{
      width: 150px;
      height: 150px;
    }
    p{
      font-size: 21px;
      color: #ffffff;
      padding: 6px 0 37px;
    }
    button{
      width: 252px;
      height: 67px;
      background: linear-gradient(257deg, #841FC3 0%, #FC3C02 100%);
      border-radius: 33px;
      border: none;
      color: #ffffff;
    }
  }
</style>